home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-MIPS / MMU_CONT.{23 < prev    next >
Text File  |  1999-09-17  |  4KB  |  135 lines

  1. /* $Id: mmu_context.h,v 1.3 1998/10/16 19:22:54 ralf Exp $
  2.  *
  3.  * Switch a MMU context.
  4.  *
  5.  * This file is subject to the terms and conditions of the GNU General Public
  6.  * License.  See the file "COPYING" in the main directory of this archive
  7.  * for more details.
  8.  *
  9.  * Copyright (C) 1996, 1997, 1998 by Ralf Baechle
  10.  */
  11. #ifndef __ASM_MIPS_MMU_CONTEXT_H
  12. #define __ASM_MIPS_MMU_CONTEXT_H
  13.  
  14. /* Fuck.  The f-word is here so you can grep for it :-)  */
  15. extern unsigned long asid_cache;
  16.  
  17. /* I patch, therefore I am ...  */
  18. #define ASID_INC(asid)                        \
  19.  ({ unsigned long __asid = asid;                \
  20.    __asm__("1:\taddiu\t%0,0\t\t\t\t# patched\n\t"        \
  21.            ".section\t__asid_inc,\"a\"\n\t"            \
  22.            ".word\t1b\n\t"                    \
  23.            ".previous"                        \
  24.            :"=r" (__asid)                    \
  25.            :"0" (__asid));                    \
  26.    __asid; })
  27. #define ASID_MASK(asid)                        \
  28.  ({ unsigned long __asid = asid;                \
  29.    __asm__("1:\tandi\t%0,%1,0\t\t\t# patched\n\t"            \
  30.            ".section\t__asid_mask,\"a\"\n\t"            \
  31.            ".word\t1b\n\t"                    \
  32.            ".previous"                        \
  33.            :"=r" (__asid)                    \
  34.            :"r" (__asid));                    \
  35.    __asid; })
  36. #define ASID_VERSION_MASK                    \
  37.  ({ unsigned long __asid;                    \
  38.    __asm__("1:\tli\t%0,0\t\t\t\t# patched\n\t"            \
  39.            ".section\t__asid_version_mask,\"a\"\n\t"        \
  40.            ".word\t1b\n\t"                    \
  41.            ".previous"                        \
  42.            :"=r" (__asid));                    \
  43.    __asid; })
  44. #define ASID_FIRST_VERSION                    \
  45.  ({ unsigned long __asid = asid;                \
  46.    __asm__("1:\tli\t%0,0\t\t\t\t# patched\n\t"            \
  47.            ".section\t__asid_first_version,\"a\"\n\t"        \
  48.            ".word\t1b\n\t"                    \
  49.            ".previous"                        \
  50.            :"=r" (__asid));                    \
  51.    __asid; })
  52.  
  53. #define ASID_FIRST_VERSION_R3000 0x1000
  54. #define ASID_FIRST_VERSION_R4000 0x100
  55.  
  56. extern inline void
  57. get_new_mmu_context(struct mm_struct *mm, unsigned long asid)
  58. {
  59.     if (!ASID_MASK((asid = ASID_INC(asid)))) {
  60.         flush_tlb_all(); /* start new asid cycle */
  61.         if (!asid)      /* fix version if needed */
  62.             asid = ASID_FIRST_VERSION;
  63.     }
  64.     mm->context = asid_cache = asid;
  65. }
  66.  
  67. extern inline void
  68. get_mmu_context(struct task_struct *p)
  69. {
  70.     struct mm_struct *mm = p->mm;
  71.  
  72.     if (mm) {
  73.         unsigned long asid = asid_cache;
  74.         /* Check if our ASID is of an older version and thus invalid */
  75.         if ((mm->context ^ asid) & ASID_VERSION_MASK)
  76.             get_new_mmu_context(mm, asid);
  77.     }
  78. }
  79.  
  80. /*
  81.  * Initialize the context related info for a new mm_struct
  82.  * instance.
  83.  */
  84. extern inline void init_new_context(struct mm_struct *mm)
  85. {
  86.     mm->context = 0;
  87. }
  88.  
  89. /*
  90.  * Destroy context related info for an mm_struct that is about
  91.  * to be put to rest.
  92.  */
  93. extern inline void destroy_context(struct mm_struct *mm)
  94. {
  95.     mm->context = 0;
  96. }
  97.  
  98. /*
  99.  * After we have set current->mm to a new value, this activates
  100.  * the context for the new mm so we see the new mappings.
  101.  */
  102. extern inline void activate_context(struct task_struct *tsk)
  103. {
  104.     get_mmu_context(tsk);
  105.     set_entryhi(tsk->mm->context);
  106. }
  107.  
  108. extern void __asid_setup(unsigned int inc, unsigned int mask,
  109.                          unsigned int version_mask, unsigned int first_version);
  110.  
  111. extern inline void r3000_asid_setup(void)
  112. {
  113.     __asid_setup(0x40, 0xfc0, 0xf000, ASID_FIRST_VERSION_R3000);
  114. }
  115.  
  116. extern inline void r6000_asid_setup(void)
  117. {
  118.     panic("r6000_asid_setup: implement me");    /* No idea ...  */
  119. }
  120.  
  121. extern inline void tfp_asid_setup(void)
  122. {
  123.     panic("tfp_asid_setup: implement me");    /* No idea ...  */
  124. }
  125.  
  126. extern inline void r4xx0_asid_setup(void)
  127. {
  128.     __asid_setup(1, 0xff, 0xff00, ASID_FIRST_VERSION_R4000);
  129. }
  130.  
  131. /* R10000 has the same ASID mechanism as the R4000.  */
  132. #define andes_asid_setup r4xx0_asid_setup
  133.  
  134. #endif /* __ASM_MIPS_MMU_CONTEXT_H */
  135.